﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;

namespace AdornerTest
{

	public class CopyItemCommand : ICommand
	{
		public event EventHandler CanExecuteChanged;

		public bool CanExecute(object parameter)
		{
			return true;
		}

		public void Execute(object parameter)
		{
			try
			{
				string sobj = JsonConvert.SerializeObject(parameter);

				Clipboard.SetText(sobj);
			}
			catch (Exception EX)
			{
				Console.WriteLine(EX.Message);
			}

		}
	}

	/// <summary>
	/// Serialize the selected item and place it on the clipboard.
	/// </summary>
	public class PasteItemCommand : ICommand
	{
		public event EventHandler CanExecuteChanged;

		public bool CanExecute(object parameter)
		{
			return true;
		}

		public void Execute(object parameter)
		{
			try
			{
				ItemsControl ic = parameter as ItemsControl;

				ObservableCollection<SomeItem> i = parameter as ObservableCollection<SomeItem>;

				var x = JsonConvert.DeserializeObject<SomeItem>(Clipboard.GetText());
				x.Top = 0;
				x.Left = 0;
				x.Name = "Copy of " + x.Name;
				(ic.ItemsSource as ObservableCollection<SomeItem>).Add(x);
			}
			catch (Exception EX)
			{
				Console.WriteLine(EX.Message);
			}

		}
	}
}
